#include("../_common/form_input.html")
#include("../_common/form_radio.html")
#include("../_common/form_textarea.html")
#include("../_common/upload_image.html")
#@admin_header()
<!-- 内容主体区域 -->
<div class="layui-body">
  <div style="padding: 15px;">
    <form class="layui-form layui-form-pane">
      #@form_input("site_name", "站点名称", dp.getSiteName(), "请输入站点名称", "站点名称，将显示在浏览器窗口标题等位置")
      #@upload_image("site_logo", "网站logo", dp.getSiteLogo(), "这里显示的是图片的路径", "就是网站的logo，左上角那里，看见没")
      #@form_input("site_root", "根网址", dp.getSiteRoot(), "请输入网站根网址", "网站 URL，请以http://开头")
      #@form_input("icp", "备案号", dp.getSiteICP(), "请输入网站备案号", "在此输入网站ICP备案号，它将显示在页面底部")
      #@form_input("copyright", "版权信息", dp.getSiteCopyright(), "请输入网站版权信息", "在此输入网站版权信息，它将显示在页面底部")
      #setLocal(map1 = {"name":"site_status","value":"open","title":"开", "checked":dp.getSiteStatus()==com.ywyself.model.Option::STATUS_OPEN?"checked":""})
      #setLocal(map2 = {"name":"site_status","value":"close","title":"关", "checked":dp.getSiteStatus()==com.ywyself.model.Option::STATUS_CLOSE?"checked":""})
      #setLocal(list = {k1:map1, k2:map2})
      #@form_radio(list, "网站状态", "网站是否开启")
      <div id="close_reason" style="display: none;">
        #@form_textarea("close_reason", "关站原因", dp.getSiteCloseReason(), "请输入网站关闭原因", "网站禁止访问的原因，将展示给所有访问本站的访客")
      </div>
      <div class="layui-form-item">
        <div class="layui-input-block">
          <button class="layui-btn" lay-filter="baseConfig" lay-submit="">立即提交</button>
          <button class="layui-btn layui-btn-primary" type="reset">重置</button>
        </div>
      </div>
    </form>
  </div>
</div>
<script>
  //JavaScript代码区域
  layui.use('form', function () {
    var form = layui.form;
    showReason('#(dp.getSiteStatus() == com.ywyself.model.Option :: STATUS_CLOSE ? "close" : "open")');
    form.render();
    form.on('radio(site_status)', function (data) {
      showReason(data.value);
    });

    function showReason(value) {
      if (value == 'close') {
        $('#close_reason').show();
      } else {
        $('#close_reason').hide()
      }
    }

    // 自定义验证
    form.verify({
      site_name: function (value) {
        if (value == '') {
          return '请输入站点名称';
        }
      },
      site_root: function (value) {
        if (value == '') {
          return '请输入网站根网址';
        }
      },
      site_status: function (value) {
        if (value == '') {
          return '网站是否开启';
        }
      }
    });
    // 提交
    form.on('submit(baseConfig)', function (data) {
      ToastLoading('正在保存...');
      $.post("#(adminRoot)/setting/base/save", data.field)
        .success(function (ret) {
          ToastShow(ret.code, ret.msg, ret.url);
        })
        .error(function () {
          ToastErr('网络错误');
        })
      // $.ajax({
      //   url : "#(adminRoot)/setting/base/save",
      //   type : "post",
      //   data : data.field,
      //   success : function(ret){ ToastShow(ret.code, ret.msg, ret.url); },
      //   error : function(ret){
      //     notice('05', '网络错误');
      //   }
      // });
      return false;
    });
  });
</script>
#@admin_footer()
